package com.student.Activitys.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.student.Activitys.R;
import com.student.Activitys.adapter.base.BaseRefreshAdapter;
import com.student.Activitys.adapter.viewholder.FooterViewHolder;
import com.student.Activitys.adapter.viewholder.ImageTextViewHolder;
import com.student.Activitys.bean.ImageTextBean;
import com.student.Activitys.utils.Constant;
import com.student.Activitys.utils.FrescoUtils;

import java.util.List;

/**
 * 项目名称：智慧校园学生端
 * 类描述：首页：校内动态 + 奖惩：奖惩资助 实体类（图文信息）adapter
 * 创建人：张飞祥
 * 创建时间：2017/10/9 9:13
 * 修改人：张飞祥
 * 修改时间：2017/10/9 9:13
 * 修改备注：
 */
public class ImageTextAdapter extends BaseRefreshAdapter {

    Context context;
    List<ImageTextBean> list;

    //上拉加载更多状态-默认为0
    private int mLoadMoreStatus = 0;

    public ImageTextAdapter(Context context, List<ImageTextBean> list) {
        super(context, list);
        this.context = context;
        this.list = list;
    }


    @Override
    protected int getLayoutItmeResId() {
        return R.layout.item_image_text;
    }

    @Override
    protected int getLayoutFootResId() {
        return R.layout.layout_load_footview;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ImageTextViewHolder) {
            ImageTextViewHolder viewHolder = (ImageTextViewHolder) holder;
            //将数据保存在itemView的Tag中，以便点击时进行获取
            viewHolder.itemView.setTag(position);
            //判断 图片是否为空
            if (list.get(position).getXXT_url().equals("")) {
                viewHolder.svItemImageTextIcon.setVisibility(View.GONE);    //隐藏
            } else {
                viewHolder.svItemImageTextIcon.setVisibility(View.VISIBLE); //显示
                FrescoUtils.loadImage(list.get(position).getXXT_url(), viewHolder.svItemImageTextIcon);
            }
            //判断 标签内容是否 为空
            if (list.get(position).getType()!=null){
                switch (list.get(position).getType()){

                    case Constant.SUPPORT_SCHOLARSHIP:      //奖学金   （金色）
                        //设置tag样式
                        viewHolder.tvItemImageTextTag.setBackgroundResource(R.drawable.public_tag_golden);
                        //设置字体颜色
                        viewHolder.tvItemImageTextTag.setTextColor(Color.parseColor("#ff9900"));
                        break;
                    case Constant.SUPPORT_A_GRANT:          //助学金   （红色）
                        //设置tag样式
                        viewHolder.tvItemImageTextTag.setBackgroundResource(R.drawable.public_tag_red);
                        //设置字体颜色
                        viewHolder.tvItemImageTextTag.setTextColor(Color.RED);
                        break;
                    case Constant.SUPPORT_PUNISHMENT:       //惩罚公告 （蓝色）
                        //设置tag样式
                        viewHolder.tvItemImageTextTag.setBackgroundResource(R.drawable.public_tag_blue);
                        //设置字体颜色
                        viewHolder.tvItemImageTextTag.setTextColor(Color.parseColor("#5BB4EC"));
                        break;
                }
                viewHolder.tvItemImageTextTag.setVisibility(View.VISIBLE); //显示
                viewHolder.tvItemImageTextTag.setText(list.get(position).getType());
            }else{
                viewHolder.tvItemImageTextTag.setVisibility(View.GONE);    //隐藏
            }
            viewHolder.tvItemImageTextTitle.setText(list.get(position).getTitle());     //标题
            viewHolder.tvItemImageTextTime.setText(list.get(position).getAddtime());    //时间
            viewHolder.tvItemImageTextBrowse.setText(list.get(position).getLLCS());     //浏览次数
        } else if (holder instanceof FooterViewHolder) {
            FooterViewHolder footViewHolder = (FooterViewHolder) holder;
            switch (mLoadMoreStatus) {
                case Constant.PULLUP_LOAD_MORE:
                    footViewHolder.pbLoad.setVisibility(View.GONE);
                    footViewHolder.tvLoadText.setText("上拉加载更多");
                    break;
                case Constant.LOADING_MORE:
                    footViewHolder.pbLoad.setVisibility(View.VISIBLE);
                    footViewHolder.tvLoadText.setText("正加载更多...");
                    break;
                case Constant.NO_LOAD_MORE:
                    //隐藏加载更多
                    footViewHolder.pbLoad.setVisibility(View.GONE);
                    footViewHolder.tvLoadText.setText("没有更多数据可加载了...");
                    break;
            }
        }
    }

    @Override
    public void changeMoreStatus(int status) {
        mLoadMoreStatus = status;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new ImageTextViewHolder(view);
    }
}
